package com.my.filter;


import jakarta.servlet.*;
import lombok.extern.slf4j.Slf4j;

import java.io.IOException;

@Slf4j
//@WebFilter("/*")
public class FilterDemo implements Filter {
    // 初始化 开始调用一次
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        log.info("FilterDemo init");
    }

    // 每次拦截后都会调用此方法
    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        log.info("FilterDemo doFiltering..放行前");

        // 放行
        filterChain.doFilter(servletRequest, servletResponse);

        log.info("放行后逻辑00");
    }

    // 正常关闭后触发一次
    @Override
    public void destroy() {
        log.info("FilterDemo destroy");
    }
}
